-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Handle pathlib.Path in write_image #2974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hello @jonmmease and @nicolaskruchten, from my point of view this looks ready to go. I'd like to know what you think. The only failing tests are also failing for I'm used to being able to use What I find especially nice here is that it works with the |
Thanks for this PR, and sorry for the radio-silence! I'll review it soon... we're planning on releasing v5.0 of |
I don't have time now, but it looks like one of the tests is failing in python-2.7-optional: =================================== FAILURES ===================================
_______________________ test_kaleido_engine_write_image ________________________
def test_kaleido_engine_write_image():
> for writeable_mock in make_writeable_mocks():
plotly/tests/test_optional/test_kaleido/test_kaleido.py:86:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
plotly/tests/test_optional/test_kaleido/test_kaleido.py:44: in make_writeable_mocks
mock_pathlib_path.active_write_function = mock_pathlib_path.write_bytes
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Mock spec='Path' id='140019672186256'>, name = 'write_bytes'
def __getattr__(self, name):
if name in ('_mock_methods', '_mock_unsafe'):
raise AttributeError(name)
elif self._mock_methods is not None:
if name not in self._mock_methods or name in _all_magics:
> raise AttributeError("Mock object has no attribute %r" % name)
E AttributeError: Mock object has no attribute 'write_bytes'
.tox/py27-optional/lib/python2.7/site-packages/mock/mock.py:698: AttributeError
____________________ test_kaleido_engine_write_image_kwargs ____________________
def test_kaleido_engine_write_image_kwargs():
> for writeable_mock in make_writeable_mocks():
plotly/tests/test_optional/test_kaleido/test_kaleido.py:119:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
plotly/tests/test_optional/test_kaleido/test_kaleido.py:44: in make_writeable_mocks
mock_pathlib_path.active_write_function = mock_pathlib_path.write_bytes
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Mock spec='Path' id='140019760188304'>, name = 'write_bytes'
def __getattr__(self, name):
if name in ('_mock_methods', '_mock_unsafe'):
raise AttributeError(name)
elif self._mock_methods is not None:
if name not in self._mock_methods or name in _all_magics:
> raise AttributeError("Mock object has no attribute %r" % name)
E AttributeError: Mock object has no attribute 'write_bytes'
.tox/py27-optional/lib/python2.7/site-packages/mock/mock.py:698: AttributeError |
That's looking much better now. I'm fairly confident that the failing tests are not caused by my changes. Please let me know if I should squash or rebase. |
@jonmmease thoughts on making |
|
Gotcha. We're dropping support for Python < 3.6 actually in the next release so this pathlib2 dependency won't be necessary then :) |
import json | ||
import plotly | ||
from plotly.io._utils import validate_coerce_fig_to_dict | ||
|
||
if sys.version_info >= (3, 4): | ||
from pathlib import Path, PurePath | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this, as we're dropping support for 2.7 and 3.5 in the next Plotly.py release.
|
||
if sys.version_info >= (3, 4): | ||
from pathlib import Path | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this, as we're dropping support for 2.7 and 3.5 in the next Plotly.py release.
@@ -10,3 +10,6 @@ six==1.8.0 | |||
|
|||
## retrying requests ## | |||
retrying==1.3.3 | |||
|
|||
## Allow pathlib2 as pathlib substitute for old Python versions ## |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this, as we're dropping support for 2.7 and 3.5 in the next Plotly.py release.
packages/python/plotly/setup.py
Outdated
@@ -505,7 +505,7 @@ def run(self): | |||
), | |||
("etc/jupyter/nbconfig/notebook.d", ["plotlywidget.json"]), | |||
], | |||
install_requires=["retrying>=1.3.3", "six"], | |||
install_requires=["retrying>=1.3.3", "six", 'pathlib2;python_version<"3.4"'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this, as we're dropping support for 2.7 and 3.5 in the next Plotly.py release.
If you can remove the |
Hello @nicolaskruchten, thanks so much for the review! As requested, I have rebased and removed the legacy support. As far as I can tell, the failing tests are not my fault. |
Hmmm are you sure you rebased onto the latest master? the name of some of those CI jobs are out of date :) |
@nicolaskruchten ya, Give me another minute and I'll fix |
Thanks! I think if you're on a roll, |
Ah, and I just realized that the actual implementation of the sort-of abstract |
(thanks so much for all the work on this, I really appreciate it :) ) |
@nicolaskruchten, thank you for writing amazing open-source software!!! Hopefully that does it. I'm not terribly pleased with all the code duplication, but I'm not so sure how you would want to refactor it. (There was already similar duplication in the original code.) |
This is awesome, thank you, and thanks for thinking of I'll poke at it a little bit more locally but this looks good to merge shortly, and certainly we'll get these changes in to v5 when it comes out in a couple of weeks. The duplication is a bit gross indeed but it's not your fault you didn't make anything worse ;) |
Note: I couldn't find the proper place to write pathlib tests for orca, so I didn't write any. I'm not sure how much you care? I like kaleido way better!!! (Did you choose the name just so you could make the pun with "scope"? 😆 If so, that's true dedication!) |
I kind of think that's why @jonmmease chose it, yes :P |
Looks awesome, thanks again :) |
Closes #2753
Code PR
plotly.graph_objects
, my modifications concern thecodegen
files and not generated files.modified existing tests.
new tutorial notebook (please see the doc checklist as well).